package com.generator.util;



import cn.hutool.core.date.DateUtil;
import com.generator.base.BaseEntity;
import com.generator.util.DateUtils;
import com.generator.util.IdUtils;

import java.util.Date;

/**
 * 基础类预处理
 *
 * @Author: ljt
 * @Date: 2020/8/27 17:07
 */
public class PreUtils {

    /**
     * 删除状态[0:正常,1:删除]
     */
    private static Integer DB_NOT_DELETED = 0;
    private static Integer DB_IS_DELETED = 1;


    private PreUtils() {
    }

    public static <T extends BaseEntity> void preSave(T entity) {
//        Integer userId = SecurityUtils.getUserIdAsVisitor();
        entity.setId(IdUtils.getNextId());
        Date now = DateUtil.date();
        entity.setCreateTime(now);
        entity.setUpdateTime(now);
//        entity.setCreateBy(userId);
//        entity.setUpdateBy(userId);
        entity.setDelFlag(DB_NOT_DELETED);
    }

    public static <T extends BaseEntity> void preUpdate(T entity) {
//        Integer userId = SecurityUtils.getUserIdAsVisitor();
        Date now = DateUtils.getNowDate();
        entity.setUpdateTime(now);
//        entity.setUpdateBy(userId);
    }

}
